package com.yogee.topseller.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.core.base.HttpActivity;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.topseller.R;
import com.yogee.topseller.adapter.ExpressDetailAdapter;
import com.yogee.topseller.bean.ExpressDetailBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.GlideUtils;

import butterknife.BindView;
import butterknife.OnClick;

public class ExpressDetailActivity extends HttpActivity {

    @BindView(R.id.title_white_left_back)
    LinearLayout titleWhiteLeftBack;
    @BindView(R.id.title_white_title)
    TextView titleWhiteTitle;
    @BindView(R.id.rl_express_detail_content)
    RecyclerView rlExpressDetailContent;
    @BindView(R.id.tv_express_type)
    TextView tvExpressType;
    @BindView(R.id.tv_express_order_id)
    TextView tvExpressOrderId;
    @BindView(R.id.tv_express_name)
    TextView tvExpressName;
    @BindView(R.id.tv_express_phone)
    TextView tvExpressPhone;
    @BindView(R.id.iv_express_img)
    ImageView ivExpressImg;
    private String proId;

    private ExpressDetailAdapter mAdapter;//物流详情列表适配器

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_express_detail;
    }

    @Override
    protected void initView() {
        if (getIntent() != null) {
            proId = getIntent().getStringExtra("proId");
        }
        titleWhiteTitle.setText("物流详情");
        rlExpressDetailContent.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new ExpressDetailAdapter(this);
        rlExpressDetailContent.setAdapter(mAdapter);
        loadExpressData();
    }

    /**
     * 获取物流详情
     */
    private void loadExpressData() {
        HttpManager.getInstance().readOrderDis(proId, AppUtil.getUserId(ExpressDetailActivity.this)).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<ExpressDetailBean>() {
            @Override
            public void onNext(ExpressDetailBean o) {
                if (null != o.getImg()) {
                    GlideUtils.defultImage(ExpressDetailActivity.this,o.getImg(),ivExpressImg);
                }
                if (null != o.getDisType()) {
                    tvExpressType.setText(o.getDisType());
                }
                if (null != o.getNum()) {
                    tvExpressOrderId.setText("单号："+o.getNum());
                }
                if (null != o.getPeople()) {
                    tvExpressName.setText("承运人："+o.getPeople());
                }
                if (null != o.getPhone()) {
                    tvExpressPhone.setText("联系电话："+o.getPhone());
                }
                if (null != o.getDisMessage()){
                    mAdapter.addData(o.getDisMessage());
                }
            }
        }, this));
    }

    @OnClick(R.id.title_white_left_back)
    public void onViewClicked() {
        if (AppUtil.isFastDoubleClick(500)) {
            return;
        }
        finish();
    }
    
}